
package com.blog.basic.interceptor;

import com.blog.entity.AdminUser;
import org.springframework.stereotype.Component;
import org.springframework.web.servlet.HandlerInterceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;


/**
 * @program: blog
 * @description: 后台登陆拦截
 * @author: Mr.zhao
 * @create: 2022-04-05 15:37
 **/
@Component
public class LoginIntercepetor implements HandlerInterceptor {

    /**
    * @Description: 登陆拦截器 登陆过后判断用户是否存在 存在即放行可以执行后续操作 ,不存在重定向到后台登陆
    * @Param:
    * @return:
    * @Author: Mr.Zhao
    * @Date: 2022/4/5
    */
    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        //可以做扩展关于记住我的功能 还有 菜单权限
        AdminUser user = (AdminUser)request.getSession().getAttribute("admin");
        if(user!=null){
            return true;
        }
        response.sendRedirect("http://localhost:8080/article/index");
        return false;
    }
}

